//
//  TableOrderController.m
//  MobileSail
//
//  Created by Roy Brown on 8/8/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "TableOrderController.h"
#import "MobileSailAppDelegate.h"

@implementation TableOrderController

@synthesize orderViewController;

- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"Table Orders";
	
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark Table view methods

//[UIView beginAnimations:nil context:NULL];
//[UIView setAnimationDuration: 0.5];
//[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
//[self.navigationController pushViewController:pickViewController animated:NO];
//[UIView commitAnimations];


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return 1;
	MobileSailAppDelegate *appDelegate = (MobileSailAppDelegate *)[[UIApplication sharedApplication] delegate];
	return appDelegate.items.count;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    /*
	 static NSString *MyIdentifier = @"MyIdentifier";
	 
	 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
	 if (cell == nil) {
	 cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
	 }
	 [cell setText:@"Table Order"];
	 // Set up the cell...
	 */
	static NSString *MyIdentifier = @"MyIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
    }
    
	MobileSailAppDelegate *appDelegate = (MobileSailAppDelegate *)[[UIApplication sharedApplication] delegate];
	MainMenuItems *i = (MainMenuItems *)[appDelegate.items objectAtIndex:indexPath.row];
	
    [cell setText:i.name];
	
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
	// [self.navigationController pushViewController:anotherViewController];
	// [anotherViewController release];
	
	if (self.orderViewController == nil)
	{
		OrderViewController *orders = [[OrderViewController alloc] initWithNibName:@"Orders" bundle:[NSBundle mainBundle]];
		self.orderViewController = orders;
		[orders release];
	}
	
	[self.navigationController pushViewController:self.orderViewController animated:YES];
}

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}


@end
